aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/[username]/dashboard
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-11-02 19:47:29 -0700
committerAdam Soltys <[email protected]>2022-11-02 19:48:18 -0700
commit23ffc5a6359dbc84a1de1da632412edeb9989b5f (patch)
tree1cc276efeb5287e1fc176ec60d46aed091ab08ca /src/routes/(app)/[username]/dashboard
parentc12857a38eed1227ed51dc6e0af7242e66dd7561 (diff)
downloadcoinos-ui-23ffc5a6359dbc84a1de1da632412edeb9989b5f.tar.gz
coinos-ui-23ffc5a6359dbc84a1de1da632412edeb9989b5f.zip
move to app layout
Diffstat (limited to 'src/routes/(app)/[username]/dashboard')
-rw-r--r--src/routes/(app)/[username]/dashboard/+page.server.js1
-rw-r--r--src/routes/(app)/[username]/dashboard/+page.svelte76
2 files changed, 77 insertions, 0 deletions
diff --git a/src/routes/(app)/[username]/dashboard/+page.server.js b/src/routes/(app)/[username]/dashboard/+page.server.js
new file mode 100644
index 00000000..b6206324
--- /dev/null
+++ b/src/routes/(app)/[username]/dashboard/+page.server.js
@@ -0,0 +1 @@
+export const load = ({ parent }) => parent();
diff --git a/src/routes/(app)/[username]/dashboard/+page.svelte b/src/routes/(app)/[username]/dashboard/+page.svelte
new file mode 100644
index 00000000..160887e3
--- /dev/null
+++ b/src/routes/(app)/[username]/dashboard/+page.svelte
@@ -0,0 +1,76 @@
+<script>
+ import { f, s, post, failure, sats } from '$lib/utils';
+ import { tick } from 'svelte';
+ import { Icon } from '$comp';
+ import { rate, selectedRate } from '$lib/store';
+ import { goto } from '$app/navigation';
+ import { t } from '$lib/translations';
+
+ export let data;
+
+ let ease = (t) => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t);
+ let interval;
+
+ $: animateRate($selectedRate);
+ let animateRate = (newRate) => {
+ if (!accountBalanceFiat) return;
+ let t = 0;
+ let newBalance = (user.account.balance * newRate) / sats;
+ let oldBalance = parseFloat(accountBalanceFiat);
+ let diff = oldBalance - newBalance;
+
+ clearInterval(interval);
+ interval = setInterval(() => {
+ let delta = diff * ease(t / 100);
+ accountBalanceFiat = (oldBalance - delta).toFixed(2);
+ if (t > 80) clearInterval(interval);
+ t++;
+ }, 10);
+ };
+
+ $: user = data.user;
+ $: accountBalanceFiat =
+ accountBalanceFiat ||
+ (user && $selectedRate && ((user.account.balance * $selectedRate) / sats).toFixed(2));
+
+ let payreq = '',
+ payreqField,
+ loading;
+
+ $: btcPrice = f($selectedRate, user.currency);
+
+ $: accountBalanceBtc = user.account.balance / sats;
+
+ $: accountBalanceSats = s(user.account.balance);
+</script>
+
+<div class="container px-4 max-w-md mx-auto mt-20">
+ <div class="text-5xl font-bold mb-2">
+ {$selectedRate ? f(accountBalanceFiat, user.currency) : $t('user.dashboard.fetchingRate')}
+ </div>
+
+ <div class="text-secondary text-2xl">
+ {accountBalanceSats} SAT
+ </div>
+
+ <div class="grid sm:grid-cols-2 gap-2 mt-8">
+ <a href={`/${user.username}/receive`}>
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >{$t('user.dashboard.receive')}</button
+ >
+ </a>
+ {#if user.account.balance > 0}
+ <a href="/send">
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >{$t('user.dashboard.withdraw')}</button
+ >
+ </a>
+ {:else}
+ <a href={`/${user.username}/settings`}>
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >Setup Account</button
+ >
+ </a>
+ {/if}
+ </div>
+</div>